package com.example.springboot.controller.web;

import cn.hutool.core.util.StrUtil;
import com.example.springboot.common.Result;
import com.example.springboot.entity.User;
import com.example.springboot.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * 功能: 提供接口，返回数据
 * 作者：八滴水
 * 日期： 2024/11/18 16:04
 */
@RestController
public class WebController {
    @Resource
    UserService userservice;
    @GetMapping("/")
    public Result hello(){
        return Result.success("success");}
    /*@PostMapping("/login")
    public Result login(@RequestBody User user) {
        if (StrUtil.isBlank(user.getUsername()) || StrUtil.isBlank(user.getPassword())) {
            return Result.error("输入不合法");
        }
        user = userservice.login(user);
        return Result.success(user);
    }*/
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        if(StrUtil.isBlank(user.getUsername()) || StrUtil.isBlank(user.getPassword())){
            return Result.error("数据错误");
        }
        User dbuser = userservice.login(user);
        return Result.success(dbuser);
    }
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        if (StrUtil.isBlank(user.getUsername()) || StrUtil.isBlank(user.getPassword())){
            return Result.error("数据错误");
        }
        User dbuser = userservice.register(user);
        return Result.success(dbuser);
    }


}
